using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;

namespace LenninSoftware.FormEditor.Adapters
{
    class Text: BaseControlAdapter
    {
        public override Control CreateReadOnlyControl(FieldInfo field)
        {
            Label label = new Label();
            return label;
        }

        public override void LoadReadOnlyData(Control control, SPListItem item, object data)
        {
            Label label = (Label)control;
            label.Text = (string)data;
        }

        public override System.Web.UI.Control CreateControl(FieldInfo field)
        {
            TextBox texBox = new TextBox();
            texBox.CssClass = "ms-long";
            return texBox;
        }

        public override void LoadData(System.Web.UI.Control control, SPListItem item, object data)
        {
            TextBox texBox = (TextBox)control;
            texBox.Text = (string)data;
        }

        public override object SaveData(System.Web.UI.Control control, SPListItem item, object currentData)
        {
            TextBox texBox = (TextBox)control;
            return texBox.Text;
        }

        public override void Reset(System.Web.UI.Control control)
        {
            TextBox texBox = (TextBox)control;
            texBox.Text = String.Empty;
        }

        public override bool isEmpty(Control control)
        {
            TextBox texBox = (TextBox)control;
            return String.IsNullOrEmpty(texBox.Text);
        }
    }
}
